//
//  ST_AIMycenterLovedST_PeculiarityCell.swift
//  btvideo
//
//  Created by mac on 2020/5/25.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SnapKit
import SwifterSwift
import HandyJSON

//MARK: - Model

class ST_AIMycenterLovedST_PeculiarityCellModel:NSObject,HandyJSON {
   
    var feature_id = 0
    
    var group_id = 0
    
    var thumb_count = 0
    
    var feature_name = ""
    
    var detail: Array<ST_PairsPeculiarityContent> = []
    
    required override init() {
        super.init()
    }
}


//MARK: - Base Cell
class ST_AIMycenterLovedST_PeculiarityCell: UICollectionViewCell {

    static let width = (ScreenWidth - 15 * 2 - 15)/2
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        contentView.backgroundColor = Color.white
        contentView.addSubview(images_container_view)
        contentView.addSubview(pec_title_label)
        contentView.addSubview(pecSubLabel)
        
        images_container_view.snp.makeConstraints { (make) in
            make.height.equalTo(images_container_view.snp.width)
            make.left.equalToSuperview().offset(0)
            make.right.equalToSuperview().offset(0)
            make.top.equalToSuperview()
        }
        
        pec_title_label.snp.makeConstraints { (make) in
            make.left.equalTo(pecSubLabel)
            make.top.equalTo(images_container_view.snp.bottom).offset(7)
            make.height.equalTo(22)
        }
        
        pecSubLabel.snp.makeConstraints { (make) in
            make.top.equalTo(pec_title_label.snp.bottom).offset(0)
            make.left.equalToSuperview().offset(5)
            make.height.equalTo(17)
        }
        
//        contentView.backgroundColor = Color.random
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
//        MARK:-Properties
//    lazy var bottom_view:UIView = {
//        let control = UIView()
////        control.cornerRadius = 10
//        control.backgroundColor = Color.white
//        return control
//    }()
    
    lazy var images_container_view:UIView = {
       let control = UIView()
        control.cornerRadius = 10
        return control
    }()
    
    lazy var pec_title_label:UILabel = {
        let control = UILabel.init()
//        control.numberOfLines = 0
        control.textColor = Color.init(hexString: "#333333")
        control.font = UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.semibold)
        return control
    }()
    
    lazy var pecSubLabel:UILabel = {
        let control = UILabel.init()
        control.text = "  "
        control.textColor = Color.init(hexString: "#ACB4C0")
        control.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.regular)
        return control
    }()

//    lazy var icon_image_view:UIImageView = {
//        let control = UIImageView()
//        control.contentMode = UIView.ContentMode.scaleAspectFill
//        control.cornerRadius = 10
//        return control
//    }()

    //    MARK:- Bind Model
    var model = ST_AIMycenterLovedST_PeculiarityCellModel(){
        didSet{
            bind_model_view()
        }
    }
    
    func bind_model_view(){
        
        pec_title_label.text = model.feature_name
        
        pecSubLabel.text = model.thumb_count.string + "特质"
    }
}

//MARK: - 单张
class ST_AIMycenterLovedSingleST_PeculiarityCell: ST_AIMycenterLovedST_PeculiarityCell {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        
        images_container_view.addSubview(cover_image_view)
        cover_image_view.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate lazy var cover_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.clipsToBounds = true
        return control
    }()
    
    
    override func bind_model_view() {
        super.bind_model_view()
        
        
        if let item = self.model.detail.first, let url = item.content.compress_image().url{

            cover_image_view.pin_setImage(from: url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
        }
    }
    
}

//MARK: - 两张
class ST_AIMycenterLovedDoubleST_PeculiarityCell: ST_AIMycenterLovedST_PeculiarityCell {
    
       override init(frame: CGRect) {
        
           super.init(frame: frame)
        
        
        images_container_view.addSubview(coverImageView1)
        coverImageView1.snp.makeConstraints { (make) in
            make.top.equalToSuperview()
            make.left.equalToSuperview()
            make.bottom.equalToSuperview()
        }
        
        images_container_view.addSubview(coverImageView2)
        coverImageView2.snp.makeConstraints { (make) in
            make.left.equalTo(coverImageView1.snp.right).offset(1)
            make.width.height.top.equalTo(coverImageView1)
            make.right.equalToSuperview()
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate lazy var coverImageView1:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.clipsToBounds = true
        return control
    }()
    
    fileprivate lazy var coverImageView2:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.clipsToBounds = true
        return control
    }()
    
    override func bind_model_view() {
        super.bind_model_view()
        
        
        if let item = self.model.detail.first,let url = item.content.compress_image().url{

            
            coverImageView1.pin_setImage(from: url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
        }

        if let item = self.model.detail[safe:1],let url = item.content.compress_image().url{

            coverImageView2.pin_setImage(from: url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
        }
        #if DEBUG
//        coverImageView1.backgroundColor = Color.random
//        coverImageView2.backgroundColor = Color.random
        #endif
    }
}
//MARK: - 三张

class ST_AIMycenterLovedThreeST_PeculiarityCell: ST_AIMycenterLovedST_PeculiarityCell {
    
    
    override init(frame: CGRect) {
           
        super.init(frame: frame)
        images_container_view.addSubview(coverImageView1)
        coverImageView1.snp.makeConstraints { (make) in
            make.top.equalToSuperview()
            make.left.equalToSuperview()
            make.bottom.equalToSuperview()
        }
        
        images_container_view.addSubview(coverImageView2)
        coverImageView2.snp.makeConstraints { (make) in
            make.left.equalTo(coverImageView1.snp.right).offset(1)
            make.right.equalToSuperview()
            make.width.top.equalTo(coverImageView1)
            
        }
        
        images_container_view.addSubview(coverImageView3)
        coverImageView3.snp.makeConstraints { (make) in
            make.left.right.equalTo(coverImageView2)
            make.top.equalTo(coverImageView2.snp.bottom).offset(1)
            make.bottom.equalTo(coverImageView1)
            make.height.equalTo(coverImageView2)
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate lazy var coverImageView1:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.clipsToBounds = true
        return control
    }()
    
    fileprivate lazy var coverImageView2:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.clipsToBounds = true
        return control
    }()
    
    fileprivate lazy var coverImageView3:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.clipsToBounds = true
        return control
    }()
    
    override func bind_model_view() {
        super.bind_model_view()
        
        
        if let item = self.model.detail.first,let url = item.content.compress_image().url{

            coverImageView1.pin_setImage(from: url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
        }
        
        if let item = self.model.detail[safe:1],let url = item.content.compress_image().url{

            coverImageView2.pin_setImage(from: url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
        }
        
        if let item = self.model.detail[safe:2],let url = item.content.compress_image().url{

            
            coverImageView3.pin_setImage(from: url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
        }
//        #if DEBUG
//        coverImageView1.backgroundColor = Color.random
//        coverImageView2.backgroundColor = Color.random
//        coverImageView3.backgroundColor = Color.random
//        #endif
    }
}

//MARK: - 四张

class ST_AIMycenterLovedQuartST_PeculiarityCell : ST_AIMycenterLovedST_PeculiarityCell {
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        images_container_view.addSubview(coverImageView1)
        images_container_view.addSubview(coverImageView2)
        images_container_view.addSubview(coverImageView3)
        images_container_view.addSubview(coverImageView4)
        
        coverImageView1.snp.makeConstraints { (make) in
            make.top.equalToSuperview()
            make.left.equalToSuperview()
            make.right.equalTo(coverImageView2.snp.left).offset(-1)
            make.bottom.equalTo(coverImageView3.snp.top).offset(-1)
        }
        
        coverImageView2.snp.makeConstraints { (make) in
            make.right.equalToSuperview()
            make.top.height.width.equalTo(coverImageView1)
        }
        
        coverImageView3.snp.makeConstraints { (make) in
            make.left.height.width.equalTo(coverImageView1)
            make.bottom.equalToSuperview()
        }
        
        coverImageView4.snp.makeConstraints { (make) in
            make.height.width.equalTo(coverImageView1)
            make.left.equalTo(coverImageView2)
            make.top.equalTo(coverImageView3)
        }
        
        
        
        
        
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate lazy var coverImageView1:ST_PairsCenterPeculiarityImageView = {
        let control = ST_PairsCenterPeculiarityImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.clipsToBounds = true
        return control
    }()
    
    fileprivate lazy var coverImageView2:ST_PairsCenterPeculiarityImageView = {
        let control = ST_PairsCenterPeculiarityImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.clipsToBounds = true
        return control
    }()
    
    fileprivate lazy var coverImageView3:ST_PairsCenterPeculiarityImageView = {
        let control = ST_PairsCenterPeculiarityImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.clipsToBounds = true
        return control
    }()
    
    fileprivate lazy var coverImageView4:ST_PairsCenterPeculiarityImageView = {
        let control = ST_PairsCenterPeculiarityImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.clipsToBounds = true
        return control
    }()
    
    override func bind_model_view() {
        super.bind_model_view()
        
        
        if let item = self.model.detail.first,let url = item.content.compress_image().url{

            coverImageView1.pin_setImage(from: url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
            coverImageView1.isCheck = item.state == 1
        }
        
        if let item = self.model.detail[safe:1],let url = item.content.compress_image().url{

            coverImageView2.pin_setImage(from: url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
            coverImageView2.isCheck = item.state == 1
        }
        
        if let item = self.model.detail[safe:2],let url = item.content.compress_image().url{

            coverImageView3.pin_setImage(from: url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
            coverImageView3.isCheck = item.state == 1
        }
        
        if let item = self.model.detail[safe:3],let url = item.content.compress_image().url{

            coverImageView4.pin_setImage(from: url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
            coverImageView4.isCheck = item.state == 1
        }
//        #if DEBUG
//        coverImageView1.backgroundColor = Color.random
//        coverImageView2.backgroundColor = Color.random
//        coverImageView3.backgroundColor = Color.random
//        coverImageView4.backgroundColor = Color.random
//        #endif
    }
}
